package nostalgia.gui;

import nostalgia.gui.forms.MainForm;
import nostalgia.gui.forms.ConfigurationDialog;
import nostalgia.UserConfiguration;

import javax.swing.*;

import de.javasoft.plaf.synthetica.SyntheticaBlueIceLookAndFeel;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Main {
    private JFrame frame;
    private MainForm mainForm;
    
    public Main() {

    }

    private void createAndShowGUI() {
        try {
            UIManager.setLookAndFeel(new SyntheticaBlueIceLookAndFeel());
        }
        catch(Exception e) {
            e.printStackTrace();
        }

        frame = new JFrame("Nostalgia.fm");
        mainForm = new MainForm();
        mainForm.getConfigurationButton().addActionListener(new ConfigurationButtonActionListener());
        frame.setContentPane(mainForm.getContentPanel());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        //frame.setExtendedState(frame.getExtendedState()|JFrame.MAXIMIZED_BOTH);
        frame.setVisible(true);

        if(!UserConfiguration.getInstsance().exists()) {
            ConfigurationDialog.showDialog(frame, true);
        }
        mainForm.load();
    }

    public class ConfigurationButtonActionListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            if(ConfigurationDialog.showDialog(frame, false)) {
                mainForm.load();
            }
        }
    }

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new Main().createAndShowGUI();
            }
        });
    }
}
